#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>

#define LISTEN 128

void TCPdaytime(const char *host, const char *service)
{
	/* buffer for noe line of test */
	char buf[LINELEN + 1];
	int s, n;
	s = connectTCP(host, service);
	while((n = read(s, buf, LINELEN)) > 0)
	{
		buf[n] = '\n';	/* last char */
		(void) fputs(buf, stdout);
	}
}

int main(int argc, char **argv)
{
	char *host = "localhost";
	char *service = "daytime";
	switch (argc) {
		case 1:
			host = "localhost";
			break;
		case 3:
			service = argv[2];
			/*FALL THROUGH */
		case 2:
			host = argv[1];
			break;
		default:
			fprintf(stderr, "usage: TCPdaytime [host [port]]\n");
			exit(1);
	}
	TCPdaytime(host, service);
	exit(0);
}
